﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutoCompleteText
{
    class Frequency
    {
        private List<String> mWord;
        private List<int> mFrequency;

        public Frequency()
        {
            mWord = new List<String>();
            mFrequency = new List<int>();
        }

        public void addWord(string word)
        {
            if(this.mWord.Contains(word))
            {
                this.mFrequency[this.mWord.IndexOf(word)]++;

            }else
            {
                this.mWord.Add(word);
                this.mFrequency.Add(1);
            }
            
        }
        public void clear()
        {

            this.mFrequency.Clear();
            this.mWord.Clear();
        }
        public List<String> getWord()
        {
            return this.mWord;

        }

        public List<int> getFrequency()
        {

            return this.mFrequency;
        }

        public void view()
        {

            OLEDBControl dbControl = new OLEDBControl();
            for(int i=0; i<this.mWord.Count; i++)
            {
                if (this.mFrequency[i] > 1)
                {
                    dbControl.DBInsert(this.mWord[i]);
                    Console.WriteLine(this.mWord[i] + ", " + this.mFrequency[i]);
                }

            }
            
        }
    }
}
